<template>
    <div>
        <div><input type="file" @change="uploadFile"></div>
        <div>图片预览：<img :src="showImage" alt=""></div>
    </div>
</template>

<script>
    import {request} from '../../assets/js/utils/request';
    export default {
    name: 'uploadfile',
    data(){
      return {
        showImage:""
      }
    },
    methods:{
      uploadFile(e){
        // console.log(e.target.files[0]);
        let file=e.target.files[0];
        let formData=new FormData();
        formData.append("headfile",file);
        let url=this.$config.baseApi+"/user/myinfo/formdatahead?token="+this.$config.token;
        // request(this.$config.baseApi+"/user/myinfo/formdatahead?token="+this.$config.token,"file",{headfile:file},config).then(res=>{
        //   if(res.code==200){
        //       this.showImage="http://vueshop.glbuys.com/userfiles/head/"+res.data.msbox;
        //     }
        // })
        // fetch(url,{
        //   method:"post",
        //   body:formData
        // }).then(res=>res.json()).then(res=>{
        //   console.log(res);
        //   if(res.code==200){
        //       this.showImage="http://vueshop.glbuys.com/userfiles/head/"+res.data.msbox;
        //     }
        // })
        request(url,"file",{headfile:file}).then(res=>{
          console.log(res);
          if(res.code==200){
              this.showImage="http://vueshop.glbuys.com/userfiles/head/"+res.data.msbox;
            }
        })
      }
    }
  };
</script>

<style scoped>

</style>
